package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.model.entity.TuiJianRen;
import com.yl.auth.model.vo.TuiJianRenVo;
import com.yl.auth.service.TuiJianRenService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.Inet4Address;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author L
 * @since 2023-06-20
 */
@Api(tags = "推荐人信息管理")
@RestController
@RequestMapping("/admin/yanglao/tuijianren")
public class TuiJianRenController {
    @Resource
    private TuiJianRenService tuiJianRenService;

    @ApiOperation(value = "推荐人全查")
    @GetMapping("/findAll")
    public Result findAll(){
        List<TuiJianRen> list = tuiJianRenService.list();
        return Result.ok(list);
    }


    @ApiOperation(value = "全查+分页+模糊查询")
    @GetMapping("/findAllConAndPage/{page}/{limit}")
    public Result findAllConAndPage(@PathVariable Integer page,
                                    @PathVariable Integer limit,
                                    TuiJianRenVo tuiJianRenVo){
        Page<TuiJianRen> tuiJianRenPage = new Page<>(page,limit);
        Page<TuiJianRen> page1 = tuiJianRenService.findAllConAndPage(tuiJianRenPage,tuiJianRenVo);
        return Result.ok(page1);
    }


    @ApiOperation(value = "新增推荐人")
    @PostMapping("/save")
    public Result save(@RequestBody TuiJianRen tuiJianRen){
        tuiJianRen.setIntegral(0L);
        tuiJianRen.setReference(0);
        tuiJianRen.setReward(0L);
        tuiJianRenService.save(tuiJianRen);
        return Result.ok();
    }
    @ApiOperation(value = "根据Id查询指定推荐人信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id){
        TuiJianRen tuiJianRen = tuiJianRenService.getById(id);
        return Result.ok(tuiJianRen);
    }
    @ApiOperation(value = "编辑推荐人")
    @PostMapping("/update")
    public Result update(@RequestBody TuiJianRen tuiJianRen){
        tuiJianRenService.updateById(tuiJianRen);
        return Result.ok();
    }

    @ApiOperation("根据Id查询推荐人信息")
    @GetMapping("/getByIdTui/{id}")
    public Result getByIdTui(@PathVariable Integer id){
        TuiJianRen tuiJianRen = tuiJianRenService.getByIdTui(id);
        return Result.ok(tuiJianRen);
    }
    @ApiOperation(value = "根据Id删除推荐人")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        tuiJianRenService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("积分设置")
    @PostMapping("/saveReward")
    public Result saveReward(@RequestBody TuiJianRen tuiJianRen){
        tuiJianRenService.updateByReward(tuiJianRen);
        return Result.ok();
    }
}

